#include <Uefi.h>

UINT32 strlen(const CHAR16* src)
{
    UINT32 len = 0;
    while(*src++ != L'\0') ++len;
    return len;
}

CHAR16* strtok(CHAR16 *s, CHAR16 *delim)
{
  static CHAR16 *p_last = NULL;
	if (s == NULL && p_last == NULL) return NULL;
	if (s == NULL)
	{
		s = p_last;
		CHAR16* tmp = p_last;
		UINT32 len = strlen(delim);
		while (*tmp)
		{
			for (UINT32 i = 0; i < len; ++i)
			{
				if (*tmp == delim[i])
				{
					p_last = tmp + 1;
					*tmp = L'\0';
					return s;
				}
			}
			tmp++;
		}
		CHAR16* ret = p_last;
		p_last = NULL;
		return ret;
	}
	else
	{
		CHAR16* tmp = s;
		UINT32 len = strlen(delim);
		while (*tmp)
		{
			for (UINT32 i = 0; i < len; ++i)
			{
				if (*tmp == delim[i])
				{
					p_last = tmp+1;
					*tmp = L'\0';
					return s;
				}
			}
			tmp++;
		}
		CHAR16* ret = p_last;
		p_last = NULL;
		return ret;
	}
}

UINT64 HexToDec(const CHAR16* src)
{
		UINT64 ret = 0;
		UINT32 len = strlen(src);
		for (UINT32 i = 2; i < len; ++i)
		{
				if (src[i] >= L'0' && src[i] <= L'9')
				{
						ret = ret * 16 + (src[i] - L'0');
				}
				else if (src[i] >= L'a' && src[i] <= L'f')
				{
						ret = ret * 16 + (src[i] - L'a' + 10);
				}
				else if (src[i] >= L'A' && src[i] <= L'F')
				{
						ret = ret * 16 + (src[i] - L'A' + 10);
				}
		}
		return ret;
}